<?php
	include('../../config/config.php');
	function createNonceStr($length = 16) {
	    $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	    $str = "";
	    for ($i = 0; $i < $length; $i++) {
	      $str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
	    }
	    return $str;
	}
	$callbacks = $_GET["callback"];
	$source = $_GET["url"];
	$noncestr =createNonceStr();
	$timestamp = time();
	//以下获取ticket
	$url = 'ticket.data';
	$html = file_get_contents($url);
	$jsonObj = json_decode($html);
	$ticket = $jsonObj->ticket;
	$time = $jsonObj->expires_in;
	if(time()>$time && !empty($time)){
	    $gettoken_de = file_get_contents(constant('domainname').'/apptoken/jssdk/get.php');
	    if(!empty($gettoken_de)){
	    header('location:echojssdk.php');
    	}
	}else{
		$string1 = "jsapi_ticket=".$ticket."&noncestr=".$noncestr."&timestamp=".$timestamp."&url=".$source;  //生成签名
		$signature = sha1($string1); //签名完成
		//$wxconfig = array('timestamp'=>$timestamp,'noncestr'=>$noncestr,'signature'=>$signature);
		//$wxconfig = json_encode($wxconfig);
		echo $callbacks.'({"configinfo":[{"timestamp":"'.$timestamp.'","noncestr":"'.$noncestr.'","signature":"'.$signature.'"}]})';
		//echo "<br>".$string1;
	}
?>
